package com.eshop.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.eshop.bean.GoodsBean;

public class AddGoodsDao {

	private Connection conn = null;
	private PreparedStatement sta = null;
	private ResultSet r = null;
	
	public int addGoods(GoodsBean bean)
	{
		int i = 0;
		try {
			conn = Conn.getConn();
			String sql = "INSERT INTO goods(brands_id,admins_id,goods_name,goods_img,goods_price," +
					"goods_stock,goods_remark,goods_description,goods_status) VALUES(?,?,?,?,?,?,?,?,?)";
			sta = conn.prepareStatement(sql);
			sta.setObject(1, bean.getBrandsId());
			sta.setObject(2, bean.getAdminsId());
			sta.setObject(3, bean.getGoodsName());
			sta.setObject(4, bean.getGoodsImg());
			sta.setObject(5, bean.getGoodsPrice());
			sta.setObject(6, bean.getGoodsStock());
			sta.setObject(7, bean.getGoodsRemark());
			sta.setObject(8, bean.getGoodsDescription());
			sta.setObject(9, bean.getGoodsStatus());
			i = sta.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				if(r != null)
				{
					r.close();
				}
				if(sta != null)
				{
					sta.close();
				}
				if(conn != null)
				{
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return i;
	}
}
